package cn.bitkit.assist.constants;

import lombok.AllArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

/**
 * @author changbo
 */
@AllArgsConstructor
public enum ClassMybatisEnum {
    /** */
    SHORT_BASE(short.class, "INTEGER"),
    SHORT(Short.class, "INTEGER"),
    BOOLEAN_BASE(boolean.class, "INTEGER"),
    BOOLEAN(Boolean.class, "INTEGER"),
    INT_BASE(int.class, "INTEGER"),
    INT(Integer.class, "INTEGER"),
    LONG_BASE(long.class, "BIGINT"),
    LONG(Long.class, "BIGINT"),
    FLOAT_BASE(float.class, "DECIMAL"),
    FLOAT(Float.class, "DECIMAL"),
    DOUBLE_BASE(double.class, "DECIMAL"),
    DOUBLE(Double.class, "DECIMAL"),
    STRING(String.class, "VARCHAR"),
    DATE(Date.class, "DATE"),
    LOCAL_DATE_TIME(LocalDateTime.class, "DATE"),
    BYTE_ARRAY(byte[].class, "BLOB"),
    BIG_DECIMAL(BigDecimal.class, "DECIMAL")
    ;
    public final Class<?> clazz;
    public final String mybatisType;

    public static ClassMybatisEnum getMybatisType(Class<?> clazz){
        return Arrays.stream(ClassMybatisEnum.values()).filter(e -> e.clazz.equals(clazz)).findFirst().orElse(null);
    }

}
